package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.BaseIdDTO;
import com.winshare.saleAssistant.domain.dto.req.ProductInfoCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.ProductInfoQueryDTO;
import com.winshare.saleAssistant.domain.dto.req.ProductInfoUpdateDTO;
import com.winshare.saleAssistant.service.ProductInfoService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/sys/product-info")
@CrossOrigin
@Api(value = "产品信息",description = "供应链管理->产品信息")
public class ProductInfoController {

    private final ProductInfoService productInfoService;

    public ProductInfoController(ProductInfoService productInfoService) {
        this.productInfoService = productInfoService;
    }

    @PostMapping("/save")
    @ApiModelProperty(value = "新增产品信息",notes = "新增产品信息")
    public LogicResponse save(@RequestBody @Validated ProductInfoCreateDTO productInfoCreateDTO) {
        productInfoService.saveProductInfo(productInfoCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiModelProperty(value = "修改产品信息",notes = "修改产品信息")
    public LogicResponse update(@RequestBody @Validated ProductInfoUpdateDTO productInfoUpdateDTO) {
        productInfoService.updateProductInfo(productInfoUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiModelProperty(value = "获取单个产品详情信息",notes = "获取单个产品详情信息")
    public LogicResponse getProductInfoDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(productInfoService.getProductInfoDetail(baseIdDTO));
    }

    @PostMapping("/delete")
    @ApiModelProperty(value = "删除单个产品接口",notes = "删除单个产品接口")
    public LogicResponse delete(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        productInfoService.deleteProductInfo(baseIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ApiModelProperty(value = "获取产品信息列表",notes = "获取产品信息列表")
    public LogicResponse getProductInfoList(@RequestBody @Validated ProductInfoQueryDTO productInfoQueryDTO) {
        return LogicResponse.success(productInfoService.getProductInfoList(productInfoQueryDTO));
    }
}
